package top.wardyan.wdev.dbdevassist.action.view;

import java.util.List;

import top.wardyan.action.base.AbstractShell;
import top.wardyan.base.model.BaseModel;
import top.wardyan.control.WTableItem;
import top.wardyan.wdev.dbdevassist.action.base.BaseMasterShell;
import top.wardyan.wdev.dbdevassist.model.YTObject;

public class ViewShell extends BaseMasterShell<ViewShell>{

	@Override
	protected List<? extends BaseModel<?>> getList() {
		return dda.viewService.list(20);
	}

	@Override
	protected AbstractShell<? extends AbstractShell<?>> mainAddShell() {
		int index = self.mainTable.getSelectionIndex();
		if(index >= 0) {
			WTableItem item = (WTableItem) self.mainTable.getItem(index);
			BaseModel<?> model = item.getModel();
			if(model != null) {
				int sID = model.getInt("sID");
				String xName = model.getStr("xName");
				return new ViewEditShell(sID, xName);
			}
		}
		return new ViewEditShell(0, "");
	}

	@Override
	protected AbstractShell<? extends AbstractShell<?>> mainEditShell(int sID) {
		int index = self.mainTable.getSelectionIndex();
		if(index >= 0) {
			WTableItem item = (WTableItem) self.mainTable.getItem(index);
			BaseModel<?> model = item.getModel();
			if(model != null) {
				String xName = model.getStr("name");
				//Proc p = dda.procService.find(xName);
				YTObject p = dda.objectService.find(xName);
				return new ViewEditShell(p != null ? p.getSID() : 0, xName);
			}
		}
		return null;
	}

	@Override
	protected String title() {
		return "视图";
	}

	
	public static void main(String[] args) {
		new ViewShell().go();
	}
}
